package com.pipayshop.controller;

import com.pipayshop.domain.StoreEvaluate;
import com.pipayshop.domain.vo.PageDataVO;
import com.pipayshop.service.PhysicalStoreEvaluateService;
import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 实体店评价 前端控制器
 * </p>
 *
 * @author zxb
 * @since 2023-07-29
 */
@Api(value = "实体店评价接口",tags = "实体店评价接口")
@RestController
@RequestMapping("/pipayshopapi/store-evaluate")
public class PhysicalStoreEvaluateController {

    @Resource
    private PhysicalStoreEvaluateService shopEvaluateService;

    @GetMapping("getShopEvaluateListByItemId/{page}/{limit}/{shopId}")
    @ApiOperation("根据实体店id获取实体店评价列表")
    public ResponseVO<PageDataVO> getShopEvaluateListByItemId(@PathVariable Integer page, @PathVariable Integer limit, @PathVariable String shopId){
        try {
            PageDataVO pageList = shopEvaluateService.getShopEvaluateListByItemId(page, limit, shopId);
            return ResponseVO.getSuccessResponseVo(pageList);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("get_evaluation_list_failed");
        }
    }

    @PostMapping("addShopEvaluate")
    @ApiOperation("增加实体店评价")
    public ResponseVO<String> addShopEvaluate(@RequestBody StoreEvaluate shopEvaluate){
        try {
            boolean result = shopEvaluateService.addShopEvaluate(shopEvaluate);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("增加实体店评价成功");
        }catch (BusinessException e) {
            throw new BusinessException(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("send_evaluation_failed");
        }
    }


    @PostMapping("deleteShopEvaluate/{evaluateId}/{userId}")
    @ApiOperation("删除实体店评价列表")
    public ResponseVO<String> deleteShopEvaluate(@PathVariable String evaluateId,@PathVariable String userId){
        try {
            boolean result = shopEvaluateService.deleteShopEvaluate(evaluateId, userId);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("删除实体店评价列表成功");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("delete_evaluation_list_failed");
        }
    }
}
